package io.geekidea.springbootplus.system.service.impl;

import io.geekidea.springbootplus.system.entity.Co;
import io.geekidea.springbootplus.system.mapper.CoMapper;
import io.geekidea.springbootplus.system.service.CoService;
import io.geekidea.springbootplus.system.param.CoPageParam;
import io.geekidea.springbootplus.system.vo.CoQueryVo;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.Serializable;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
/**
 *  服务实现类
 *
 * @author miko
 * @since 2020-10-24
 */
@Slf4j
@Service
public class CoServiceImpl extends BaseServiceImpl<CoMapper, Co> implements CoService {

    @Autowired
    private CoMapper coMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveCo(Co co) throws Exception {
        return super.save(co);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateCo(Co co) throws Exception {
        return super.updateById(co);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteCo(Long id) throws Exception {
        return super.removeById(id);
    }


    @Override
    public List<Co> getAllList(LambdaQueryWrapper<Co> wrapper) throws Exception{
        return coMapper.selectList(wrapper);
    }



    @Override
    public CoQueryVo getCoById(Serializable id) throws Exception {
    return coMapper.getCoById(id);
    }

    @Override
    public Paging<CoQueryVo> getCoPageList(CoPageParam coPageParam) throws Exception {
        Page<CoQueryVo> page = new PageInfo<>(coPageParam, OrderItem.desc(getLambdaColumn(Co::getCreateTime)));
        IPage<CoQueryVo> iPage = coMapper.getCoPageList(page, coPageParam);
        return new Paging<CoQueryVo>(iPage);
    }

}
